package classes.tfo
{
	import mx.collections.XMLListCollection;
	
	[RemoteClass(alias="com.sylli.oeuf.server.object.transferable.SkillTO")]
	[Bindable]
	public class SkillTO extends BasedTO
	{
		public var requirements:Array = [];
		public var rank:int;
		public var maxRank:int;
		public var skillName:String;
		public var description:String;
		public var skillDbName:String;
		public var type:String;
		public var icon:String;
		public var slotId:int;
		
		public function SkillTO()
		{
		}
		
		public function clone():SkillTO {
			var item:SkillTO = new SkillTO();
			item.skillName = skillName;
			item.skillDbName = skillDbName;
			item.type = type;
			item.description = description;
			item.icon = icon;
			item.slotId = slotId;
			item.rank = rank;
			item.maxRank = maxRank;
			item.requirements = requirements;
			return item;
		}
		
		public function copyAllExceptRank(item:SkillTO):void {
			this.skillName = item.skillName;
			this.skillDbName = item.skillDbName;
			this.type = item.type;
			this.description = item.description;
			this.icon = item.icon;
			this.slotId = item.slotId;
			this.maxRank = item.maxRank;
			this.requirements = item.requirements;
		}
		
		public static function createInstance(xmlElement:Object):SkillTO {
			var item:SkillTO = new SkillTO();
			item.skillName = String(xmlElement.skillName);
			item.skillDbName = String(xmlElement.skillDbName);
			item.type = String(xmlElement.type);
			item.description = String(xmlElement.description);
			item.icon = String(xmlElement.icon);
			item.slotId = int(xmlElement.slotId);
			item.maxRank = int(xmlElement.maxRank);
			
			var reqList:XMLListCollection = new XMLListCollection();
			reqList.source = xmlElement.requirements.reqEntry;
			for(var i:int = 0; i < reqList.length; i++) {
				var obj:Object = reqList.getItemAt(i);
				var skill:String = String(obj.skill);
				var level:int = int(obj.level);
				item.requirements.push({skill:skill, level:level});
			}
			return item;
		}

	}
}